<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude #-}</span><span>
</span><span id="line-3"></span><span>
</span><span id="line-4"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Module      :  Data.Maybe</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2001</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-9"></span><span class="hs-comment">--</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Stability   :  stable</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- The Maybe type, and associated operations.</span><span>
</span><span id="line-15"></span><span class="hs-comment">--</span><span>
</span><span id="line-16"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Data.Maybe</span><span>
</span><span id="line-19"></span><span>   </span><span class="hs-special">(</span><span>
</span><span id="line-20"></span><span>     </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier">Maybe</span></a></span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier">Nothing</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier">Just</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-21"></span><span>
</span><span id="line-22"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Maybe.html#maybe"><span class="hs-identifier">maybe</span></a></span><span>
</span><span id="line-23"></span><span>
</span><span id="line-24"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Maybe.html#isJust"><span class="hs-identifier">isJust</span></a></span><span>
</span><span id="line-25"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Maybe.html#isNothing"><span class="hs-identifier">isNothing</span></a></span><span>
</span><span id="line-26"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Maybe.html#fromJust"><span class="hs-identifier">fromJust</span></a></span><span>
</span><span id="line-27"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Maybe.html#fromMaybe"><span class="hs-identifier">fromMaybe</span></a></span><span>
</span><span id="line-28"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Maybe.html#listToMaybe"><span class="hs-identifier">listToMaybe</span></a></span><span>
</span><span id="line-29"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Maybe.html#maybeToList"><span class="hs-identifier">maybeToList</span></a></span><span>
</span><span id="line-30"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Maybe.html#catMaybes"><span class="hs-identifier">catMaybes</span></a></span><span>
</span><span id="line-31"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Maybe.html#mapMaybe"><span class="hs-identifier">mapMaybe</span></a></span><span>
</span><span id="line-32"></span><span>   </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Stack.Types.html"><span class="hs-identifier">GHC.Stack.Types</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Stack.Types.html#HasCallStack"><span class="hs-identifier">HasCallStack</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-36"></span><span>
</span><span id="line-37"></span><span class="hs-comment">-- $setup</span><span>
</span><span id="line-38"></span><span class="hs-comment">-- Allow the use of some Prelude functions in doctests.</span><span>
</span><span id="line-39"></span><span class="hs-comment">-- &gt;&gt;&gt; import Prelude ( (*), odd, show, sum )</span><span>
</span><span id="line-40"></span><span>
</span><span id="line-41"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-42"></span><span class="hs-comment">-- Functions over Maybe</span><span>
</span><span id="line-43"></span><span>
</span><span id="line-44"></span><span class="hs-comment">-- | The 'maybe' function takes a default value, a function, and a 'Maybe'</span><span>
</span><span id="line-45"></span><span class="hs-comment">-- value.  If the 'Maybe' value is 'Nothing', the function returns the</span><span>
</span><span id="line-46"></span><span class="hs-comment">-- default value.  Otherwise, it applies the function to the value inside</span><span>
</span><span id="line-47"></span><span class="hs-comment">-- the 'Just' and returns the result.</span><span>
</span><span id="line-48"></span><span class="hs-comment">--</span><span>
</span><span id="line-49"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-50"></span><span class="hs-comment">--</span><span>
</span><span id="line-51"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-52"></span><span class="hs-comment">--</span><span>
</span><span id="line-53"></span><span class="hs-comment">-- &gt;&gt;&gt; maybe False odd (Just 3)</span><span>
</span><span id="line-54"></span><span class="hs-comment">-- True</span><span>
</span><span id="line-55"></span><span class="hs-comment">--</span><span>
</span><span id="line-56"></span><span class="hs-comment">-- &gt;&gt;&gt; maybe False odd Nothing</span><span>
</span><span id="line-57"></span><span class="hs-comment">-- False</span><span>
</span><span id="line-58"></span><span class="hs-comment">--</span><span>
</span><span id="line-59"></span><span class="hs-comment">-- Read an integer from a string using 'Text.Read.readMaybe'. If we succeed,</span><span>
</span><span id="line-60"></span><span class="hs-comment">-- return twice the integer; that is, apply @(*2)@ to it. If instead</span><span>
</span><span id="line-61"></span><span class="hs-comment">-- we fail to parse an integer, return @0@ by default:</span><span>
</span><span id="line-62"></span><span class="hs-comment">--</span><span>
</span><span id="line-63"></span><span class="hs-comment">-- &gt;&gt;&gt; import Text.Read ( readMaybe )</span><span>
</span><span id="line-64"></span><span class="hs-comment">-- &gt;&gt;&gt; maybe 0 (*2) (readMaybe &quot;5&quot;)</span><span>
</span><span id="line-65"></span><span class="hs-comment">-- 10</span><span>
</span><span id="line-66"></span><span class="hs-comment">-- &gt;&gt;&gt; maybe 0 (*2) (readMaybe &quot;&quot;)</span><span>
</span><span id="line-67"></span><span class="hs-comment">-- 0</span><span>
</span><span id="line-68"></span><span class="hs-comment">--</span><span>
</span><span id="line-69"></span><span class="hs-comment">-- Apply 'Prelude.show' to a @Maybe Int@. If we have @Just n@, we want to show</span><span>
</span><span id="line-70"></span><span class="hs-comment">-- the underlying 'Int' @n@. But if we have 'Nothing', we return the</span><span>
</span><span id="line-71"></span><span class="hs-comment">-- empty string instead of (for example) \&quot;Nothing\&quot;:</span><span>
</span><span id="line-72"></span><span class="hs-comment">--</span><span>
</span><span id="line-73"></span><span class="hs-comment">-- &gt;&gt;&gt; maybe &quot;&quot; show (Just 5)</span><span>
</span><span id="line-74"></span><span class="hs-comment">-- &quot;5&quot;</span><span>
</span><span id="line-75"></span><span class="hs-comment">-- &gt;&gt;&gt; maybe &quot;&quot; show Nothing</span><span>
</span><span id="line-76"></span><span class="hs-comment">-- &quot;&quot;</span><span>
</span><span id="line-77"></span><span class="hs-comment">--</span><span>
</span><span id="line-78"></span><span id="local-6989586621679486656"><span id="local-6989586621679486657"><span class="annot"><a href="Data.Maybe.html#maybe"><span class="hs-identifier hs-type">maybe</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679486657"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679486656"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679486657"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486656"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679486657"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-79"></span><span id="maybe"><span class="annot"><span class="annottext">maybe :: forall b a. b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b
</span><a href="Data.Maybe.html#maybe"><span class="hs-identifier hs-var hs-var">maybe</span></a></span></span><span> </span><span id="local-6989586621679486610"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679486610"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="annot"><span class="annottext">a -&gt; b
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679486610"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-80"></span><span class="annot"><a href="Data.Maybe.html#maybe"><span class="hs-identifier hs-var">maybe</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679486609"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679486609"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679486608"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486608"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621679486609"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486608"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-81"></span><span>
</span><span id="line-82"></span><span class="hs-comment">-- | The 'isJust' function returns 'True' iff its argument is of the</span><span>
</span><span id="line-83"></span><span class="hs-comment">-- form @Just _@.</span><span>
</span><span id="line-84"></span><span class="hs-comment">--</span><span>
</span><span id="line-85"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-86"></span><span class="hs-comment">--</span><span>
</span><span id="line-87"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-88"></span><span class="hs-comment">--</span><span>
</span><span id="line-89"></span><span class="hs-comment">-- &gt;&gt;&gt; isJust (Just 3)</span><span>
</span><span id="line-90"></span><span class="hs-comment">-- True</span><span>
</span><span id="line-91"></span><span class="hs-comment">--</span><span>
</span><span id="line-92"></span><span class="hs-comment">-- &gt;&gt;&gt; isJust (Just ())</span><span>
</span><span id="line-93"></span><span class="hs-comment">-- True</span><span>
</span><span id="line-94"></span><span class="hs-comment">--</span><span>
</span><span id="line-95"></span><span class="hs-comment">-- &gt;&gt;&gt; isJust Nothing</span><span>
</span><span id="line-96"></span><span class="hs-comment">-- False</span><span>
</span><span id="line-97"></span><span class="hs-comment">--</span><span>
</span><span id="line-98"></span><span class="hs-comment">-- Only the outer constructor is taken into consideration:</span><span>
</span><span id="line-99"></span><span class="hs-comment">--</span><span>
</span><span id="line-100"></span><span class="hs-comment">-- &gt;&gt;&gt; isJust (Just Nothing)</span><span>
</span><span id="line-101"></span><span class="hs-comment">-- True</span><span>
</span><span id="line-102"></span><span class="hs-comment">--</span><span>
</span><span id="line-103"></span><span id="local-6989586621679486653"><span class="annot"><a href="Data.Maybe.html#isJust"><span class="hs-identifier hs-type">isJust</span></a></span><span>         </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486653"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span></span><span>
</span><span id="line-104"></span><span id="isJust"><span class="annot"><span class="annottext">isJust :: forall a. Maybe a -&gt; Bool
</span><a href="Data.Maybe.html#isJust"><span class="hs-identifier hs-var hs-var">isJust</span></a></span></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-105"></span><span class="annot"><a href="Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><span class="hs-identifier">_</span></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-106"></span><span>
</span><span id="line-107"></span><span class="hs-comment">-- | The 'isNothing' function returns 'True' iff its argument is 'Nothing'.</span><span>
</span><span id="line-108"></span><span class="hs-comment">--</span><span>
</span><span id="line-109"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-110"></span><span class="hs-comment">--</span><span>
</span><span id="line-111"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-112"></span><span class="hs-comment">--</span><span>
</span><span id="line-113"></span><span class="hs-comment">-- &gt;&gt;&gt; isNothing (Just 3)</span><span>
</span><span id="line-114"></span><span class="hs-comment">-- False</span><span>
</span><span id="line-115"></span><span class="hs-comment">--</span><span>
</span><span id="line-116"></span><span class="hs-comment">-- &gt;&gt;&gt; isNothing (Just ())</span><span>
</span><span id="line-117"></span><span class="hs-comment">-- False</span><span>
</span><span id="line-118"></span><span class="hs-comment">--</span><span>
</span><span id="line-119"></span><span class="hs-comment">-- &gt;&gt;&gt; isNothing Nothing</span><span>
</span><span id="line-120"></span><span class="hs-comment">-- True</span><span>
</span><span id="line-121"></span><span class="hs-comment">--</span><span>
</span><span id="line-122"></span><span class="hs-comment">-- Only the outer constructor is taken into consideration:</span><span>
</span><span id="line-123"></span><span class="hs-comment">--</span><span>
</span><span id="line-124"></span><span class="hs-comment">-- &gt;&gt;&gt; isNothing (Just Nothing)</span><span>
</span><span id="line-125"></span><span class="hs-comment">-- False</span><span>
</span><span id="line-126"></span><span class="hs-comment">--</span><span>
</span><span id="line-127"></span><span id="local-6989586621679486607"><span class="annot"><a href="Data.Maybe.html#isNothing"><span class="hs-identifier hs-type">isNothing</span></a></span><span>         </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486607"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span></span><span>
</span><span id="line-128"></span><span id="isNothing"><span class="annot"><span class="annottext">isNothing :: forall a. Maybe a -&gt; Bool
</span><a href="Data.Maybe.html#isNothing"><span class="hs-identifier hs-var hs-var">isNothing</span></a></span></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-129"></span><span class="annot"><a href="Data.Maybe.html#isNothing"><span class="hs-identifier hs-var">isNothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><span class="hs-identifier">_</span></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-130"></span><span>
</span><span id="line-131"></span><span class="hs-comment">-- | The 'fromJust' function extracts the element out of a 'Just' and</span><span>
</span><span id="line-132"></span><span class="hs-comment">-- throws an error if its argument is 'Nothing'.</span><span>
</span><span id="line-133"></span><span class="hs-comment">--</span><span>
</span><span id="line-134"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-135"></span><span class="hs-comment">--</span><span>
</span><span id="line-136"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-137"></span><span class="hs-comment">--</span><span>
</span><span id="line-138"></span><span class="hs-comment">-- &gt;&gt;&gt; fromJust (Just 1)</span><span>
</span><span id="line-139"></span><span class="hs-comment">-- 1</span><span>
</span><span id="line-140"></span><span class="hs-comment">--</span><span>
</span><span id="line-141"></span><span class="hs-comment">-- &gt;&gt;&gt; 2 * (fromJust (Just 10))</span><span>
</span><span id="line-142"></span><span class="hs-comment">-- 20</span><span>
</span><span id="line-143"></span><span class="hs-comment">--</span><span>
</span><span id="line-144"></span><span class="hs-comment">-- &gt;&gt;&gt; 2 * (fromJust Nothing)</span><span>
</span><span id="line-145"></span><span class="hs-comment">-- *** Exception: Maybe.fromJust: Nothing</span><span>
</span><span id="line-146"></span><span class="hs-comment">--</span><span>
</span><span id="line-147"></span><span id="local-6989586621679486649"><span class="annot"><a href="Data.Maybe.html#fromJust"><span class="hs-identifier hs-type">fromJust</span></a></span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Stack.Types.html#HasCallStack"><span class="hs-identifier hs-type">HasCallStack</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486649"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679486649"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-148"></span><span id="fromJust"><span class="annot"><span class="annottext">fromJust :: forall a. HasCallStack =&gt; Maybe a -&gt; a
</span><a href="Data.Maybe.html#fromJust"><span class="hs-identifier hs-var hs-var">fromJust</span></a></span></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; a
forall a. HasCallStack =&gt; [Char] -&gt; a
</span><a href="GHC.Err.html#error"><span class="hs-identifier hs-var">error</span></a></span><span> </span><span class="annot"><span class="annottext">[Char]
</span><span class="hs-string">&quot;Maybe.fromJust: Nothing&quot;</span></span><span> </span><span class="hs-comment">-- yuck</span><span>
</span><span id="line-149"></span><span class="annot"><a href="Data.Maybe.html#fromJust"><span class="hs-identifier hs-var">fromJust</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679486602"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486602"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486602"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-150"></span><span>
</span><span id="line-151"></span><span class="hs-comment">-- | The 'fromMaybe' function takes a default value and a 'Maybe'</span><span>
</span><span id="line-152"></span><span class="hs-comment">-- value.  If the 'Maybe' is 'Nothing', it returns the default value;</span><span>
</span><span id="line-153"></span><span class="hs-comment">-- otherwise, it returns the value contained in the 'Maybe'.</span><span>
</span><span id="line-154"></span><span class="hs-comment">--</span><span>
</span><span id="line-155"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-156"></span><span class="hs-comment">--</span><span>
</span><span id="line-157"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-158"></span><span class="hs-comment">--</span><span>
</span><span id="line-159"></span><span class="hs-comment">-- &gt;&gt;&gt; fromMaybe &quot;&quot; (Just &quot;Hello, World!&quot;)</span><span>
</span><span id="line-160"></span><span class="hs-comment">-- &quot;Hello, World!&quot;</span><span>
</span><span id="line-161"></span><span class="hs-comment">--</span><span>
</span><span id="line-162"></span><span class="hs-comment">-- &gt;&gt;&gt; fromMaybe &quot;&quot; Nothing</span><span>
</span><span id="line-163"></span><span class="hs-comment">-- &quot;&quot;</span><span>
</span><span id="line-164"></span><span class="hs-comment">--</span><span>
</span><span id="line-165"></span><span class="hs-comment">-- Read an integer from a string using 'Text.Read.readMaybe'. If we fail to</span><span>
</span><span id="line-166"></span><span class="hs-comment">-- parse an integer, we want to return @0@ by default:</span><span>
</span><span id="line-167"></span><span class="hs-comment">--</span><span>
</span><span id="line-168"></span><span class="hs-comment">-- &gt;&gt;&gt; import Text.Read ( readMaybe )</span><span>
</span><span id="line-169"></span><span class="hs-comment">-- &gt;&gt;&gt; fromMaybe 0 (readMaybe &quot;5&quot;)</span><span>
</span><span id="line-170"></span><span class="hs-comment">-- 5</span><span>
</span><span id="line-171"></span><span class="hs-comment">-- &gt;&gt;&gt; fromMaybe 0 (readMaybe &quot;&quot;)</span><span>
</span><span id="line-172"></span><span class="hs-comment">-- 0</span><span>
</span><span id="line-173"></span><span class="hs-comment">--</span><span>
</span><span id="line-174"></span><span id="local-6989586621679486645"><span class="annot"><a href="Data.Maybe.html#fromMaybe"><span class="hs-identifier hs-type">fromMaybe</span></a></span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679486645"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486645"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679486645"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-175"></span><span id="fromMaybe"><span class="annot"><span class="annottext">fromMaybe :: forall a. a -&gt; Maybe a -&gt; a
</span><a href="Data.Maybe.html#fromMaybe"><span class="hs-identifier hs-var hs-var">fromMaybe</span></a></span></span><span> </span><span id="local-6989586621679486601"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486601"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span id="local-6989586621679486600"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679486600"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679486600"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span class="annot"><span class="annottext">Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486601"><span class="hs-identifier hs-var">d</span></a></span><span class="hs-special">;</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679486599"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486599"><span class="hs-identifier hs-var">v</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486599"><span class="hs-identifier hs-var">v</span></a></span><span class="hs-special">}</span><span>
</span><span id="line-176"></span><span>
</span><span id="line-177"></span><span class="hs-comment">-- | The 'maybeToList' function returns an empty list when given</span><span>
</span><span id="line-178"></span><span class="hs-comment">-- 'Nothing' or a singleton list when given 'Just'.</span><span>
</span><span id="line-179"></span><span class="hs-comment">--</span><span>
</span><span id="line-180"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-181"></span><span class="hs-comment">--</span><span>
</span><span id="line-182"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-183"></span><span class="hs-comment">--</span><span>
</span><span id="line-184"></span><span class="hs-comment">-- &gt;&gt;&gt; maybeToList (Just 7)</span><span>
</span><span id="line-185"></span><span class="hs-comment">-- [7]</span><span>
</span><span id="line-186"></span><span class="hs-comment">--</span><span>
</span><span id="line-187"></span><span class="hs-comment">-- &gt;&gt;&gt; maybeToList Nothing</span><span>
</span><span id="line-188"></span><span class="hs-comment">-- []</span><span>
</span><span id="line-189"></span><span class="hs-comment">--</span><span>
</span><span id="line-190"></span><span class="hs-comment">-- One can use 'maybeToList' to avoid pattern matching when combined</span><span>
</span><span id="line-191"></span><span class="hs-comment">-- with a function that (safely) works on lists:</span><span>
</span><span id="line-192"></span><span class="hs-comment">--</span><span>
</span><span id="line-193"></span><span class="hs-comment">-- &gt;&gt;&gt; import Text.Read ( readMaybe )</span><span>
</span><span id="line-194"></span><span class="hs-comment">-- &gt;&gt;&gt; sum $ maybeToList (readMaybe &quot;3&quot;)</span><span>
</span><span id="line-195"></span><span class="hs-comment">-- 3</span><span>
</span><span id="line-196"></span><span class="hs-comment">-- &gt;&gt;&gt; sum $ maybeToList (readMaybe &quot;&quot;)</span><span>
</span><span id="line-197"></span><span class="hs-comment">-- 0</span><span>
</span><span id="line-198"></span><span class="hs-comment">--</span><span>
</span><span id="line-199"></span><span id="local-6989586621679486643"><span class="annot"><a href="Data.Maybe.html#maybeToList"><span class="hs-identifier hs-type">maybeToList</span></a></span><span>            </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486643"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679486643"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-200"></span><span id="maybeToList"><span class="annot"><span class="annottext">maybeToList :: forall a. Maybe a -&gt; [a]
</span><a href="Data.Maybe.html#maybeToList"><span class="hs-identifier hs-var hs-var">maybeToList</span></a></span></span><span>  </span><span class="annot"><span class="annottext">Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-201"></span><span class="annot"><a href="Data.Maybe.html#maybeToList"><span class="hs-identifier hs-var">maybeToList</span></a></span><span>  </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679486598"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486598"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486598"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-202"></span><span>
</span><span id="line-203"></span><span class="hs-comment">-- | The 'listToMaybe' function returns 'Nothing' on an empty list</span><span>
</span><span id="line-204"></span><span class="hs-comment">-- or @'Just' a@ where @a@ is the first element of the list.</span><span>
</span><span id="line-205"></span><span class="hs-comment">--</span><span>
</span><span id="line-206"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-207"></span><span class="hs-comment">--</span><span>
</span><span id="line-208"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-209"></span><span class="hs-comment">--</span><span>
</span><span id="line-210"></span><span class="hs-comment">-- &gt;&gt;&gt; listToMaybe []</span><span>
</span><span id="line-211"></span><span class="hs-comment">-- Nothing</span><span>
</span><span id="line-212"></span><span class="hs-comment">--</span><span>
</span><span id="line-213"></span><span class="hs-comment">-- &gt;&gt;&gt; listToMaybe [9]</span><span>
</span><span id="line-214"></span><span class="hs-comment">-- Just 9</span><span>
</span><span id="line-215"></span><span class="hs-comment">--</span><span>
</span><span id="line-216"></span><span class="hs-comment">-- &gt;&gt;&gt; listToMaybe [1,2,3]</span><span>
</span><span id="line-217"></span><span class="hs-comment">-- Just 1</span><span>
</span><span id="line-218"></span><span class="hs-comment">--</span><span>
</span><span id="line-219"></span><span class="hs-comment">-- Composing 'maybeToList' with 'listToMaybe' should be the identity</span><span>
</span><span id="line-220"></span><span class="hs-comment">-- on singleton/empty lists:</span><span>
</span><span id="line-221"></span><span class="hs-comment">--</span><span>
</span><span id="line-222"></span><span class="hs-comment">-- &gt;&gt;&gt; maybeToList $ listToMaybe [5]</span><span>
</span><span id="line-223"></span><span class="hs-comment">-- [5]</span><span>
</span><span id="line-224"></span><span class="hs-comment">-- &gt;&gt;&gt; maybeToList $ listToMaybe []</span><span>
</span><span id="line-225"></span><span class="hs-comment">-- []</span><span>
</span><span id="line-226"></span><span class="hs-comment">--</span><span>
</span><span id="line-227"></span><span class="hs-comment">-- But not on lists with more than one element:</span><span>
</span><span id="line-228"></span><span class="hs-comment">--</span><span>
</span><span id="line-229"></span><span class="hs-comment">-- &gt;&gt;&gt; maybeToList $ listToMaybe [1,2,3]</span><span>
</span><span id="line-230"></span><span class="hs-comment">-- [1]</span><span>
</span><span id="line-231"></span><span class="hs-comment">--</span><span>
</span><span id="line-232"></span><span id="local-6989586621679486640"><span class="annot"><a href="Data.Maybe.html#listToMaybe"><span class="hs-identifier hs-type">listToMaybe</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679486640"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486640"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-233"></span><span id="listToMaybe"><span class="annot"><span class="annottext">listToMaybe :: forall a. [a] -&gt; Maybe a
</span><a href="Data.Maybe.html#listToMaybe"><span class="hs-identifier hs-var hs-var">listToMaybe</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; Maybe a -&gt; Maybe a) -&gt; Maybe a -&gt; [a] -&gt; Maybe a
forall a b. (a -&gt; b -&gt; b) -&gt; b -&gt; [a] -&gt; b
</span><a href="GHC.Base.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe a -&gt; Maybe a -&gt; Maybe a
forall a b. a -&gt; b -&gt; a
</span><a href="GHC.Base.html#const"><span class="hs-identifier hs-var">const</span></a></span><span> </span><span class="annot"><span class="annottext">(Maybe a -&gt; Maybe a -&gt; Maybe a)
-&gt; (a -&gt; Maybe a) -&gt; a -&gt; Maybe a -&gt; Maybe a
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-234"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="Data.Maybe.html#listToMaybe"><span class="hs-pragma hs-type">listToMaybe</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-235"></span><span class="hs-comment">-- We define listToMaybe using foldr so that it can fuse via the foldr/build</span><span>
</span><span id="line-236"></span><span class="hs-comment">-- rule. See #14387</span><span>
</span><span id="line-237"></span><span>
</span><span id="line-238"></span><span>
</span><span id="line-239"></span><span class="hs-comment">-- | The 'catMaybes' function takes a list of 'Maybe's and returns</span><span>
</span><span id="line-240"></span><span class="hs-comment">-- a list of all the 'Just' values.</span><span>
</span><span id="line-241"></span><span class="hs-comment">--</span><span>
</span><span id="line-242"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-243"></span><span class="hs-comment">--</span><span>
</span><span id="line-244"></span><span class="hs-comment">-- Basic usage:</span><span>
</span><span id="line-245"></span><span class="hs-comment">--</span><span>
</span><span id="line-246"></span><span class="hs-comment">-- &gt;&gt;&gt; catMaybes [Just 1, Nothing, Just 3]</span><span>
</span><span id="line-247"></span><span class="hs-comment">-- [1,3]</span><span>
</span><span id="line-248"></span><span class="hs-comment">--</span><span>
</span><span id="line-249"></span><span class="hs-comment">-- When constructing a list of 'Maybe' values, 'catMaybes' can be used</span><span>
</span><span id="line-250"></span><span class="hs-comment">-- to return all of the \&quot;success\&quot; results (if the list is the result</span><span>
</span><span id="line-251"></span><span class="hs-comment">-- of a 'map', then 'mapMaybe' would be more appropriate):</span><span>
</span><span id="line-252"></span><span class="hs-comment">--</span><span>
</span><span id="line-253"></span><span class="hs-comment">-- &gt;&gt;&gt; import Text.Read ( readMaybe )</span><span>
</span><span id="line-254"></span><span class="hs-comment">-- &gt;&gt;&gt; [readMaybe x :: Maybe Int | x &lt;- [&quot;1&quot;, &quot;Foo&quot;, &quot;3&quot;] ]</span><span>
</span><span id="line-255"></span><span class="hs-comment">-- [Just 1,Nothing,Just 3]</span><span>
</span><span id="line-256"></span><span class="hs-comment">-- &gt;&gt;&gt; catMaybes $ [readMaybe x :: Maybe Int | x &lt;- [&quot;1&quot;, &quot;Foo&quot;, &quot;3&quot;] ]</span><span>
</span><span id="line-257"></span><span class="hs-comment">-- [1,3]</span><span>
</span><span id="line-258"></span><span class="hs-comment">--</span><span>
</span><span id="line-259"></span><span id="local-6989586621679486631"><span class="annot"><a href="Data.Maybe.html#catMaybes"><span class="hs-identifier hs-type">catMaybes</span></a></span><span>              </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486631"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679486631"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-260"></span><span id="catMaybes"><span class="annot"><span class="annottext">catMaybes :: forall a. [Maybe a] -&gt; [a]
</span><a href="Data.Maybe.html#catMaybes"><span class="hs-identifier hs-var hs-var">catMaybes</span></a></span></span><span> </span><span id="local-6989586621679486595"><span class="annot"><span class="annottext">[Maybe a]
</span><a href="#local-6989586621679486595"><span class="hs-identifier hs-var">ls</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486594"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679486594"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486594"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Maybe a]
</span><a href="#local-6989586621679486595"><span class="hs-identifier hs-var">ls</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-261"></span><span>
</span><span id="line-262"></span><span class="hs-comment">-- | The 'mapMaybe' function is a version of 'map' which can throw</span><span>
</span><span id="line-263"></span><span class="hs-comment">-- out elements.  In particular, the functional argument returns</span><span>
</span><span id="line-264"></span><span class="hs-comment">-- something of type @'Maybe' b@.  If this is 'Nothing', no element</span><span>
</span><span id="line-265"></span><span class="hs-comment">-- is added on to the result list.  If it is @'Just' b@, then @b@ is</span><span>
</span><span id="line-266"></span><span class="hs-comment">-- included in the result list.</span><span>
</span><span id="line-267"></span><span class="hs-comment">--</span><span>
</span><span id="line-268"></span><span class="hs-comment">-- ==== __Examples__</span><span>
</span><span id="line-269"></span><span class="hs-comment">--</span><span>
</span><span id="line-270"></span><span class="hs-comment">-- Using @'mapMaybe' f x@ is a shortcut for @'catMaybes' $ 'map' f x@</span><span>
</span><span id="line-271"></span><span class="hs-comment">-- in most cases:</span><span>
</span><span id="line-272"></span><span class="hs-comment">--</span><span>
</span><span id="line-273"></span><span class="hs-comment">-- &gt;&gt;&gt; import Text.Read ( readMaybe )</span><span>
</span><span id="line-274"></span><span class="hs-comment">-- &gt;&gt;&gt; let readMaybeInt = readMaybe :: String -&gt; Maybe Int</span><span>
</span><span id="line-275"></span><span class="hs-comment">-- &gt;&gt;&gt; mapMaybe readMaybeInt [&quot;1&quot;, &quot;Foo&quot;, &quot;3&quot;]</span><span>
</span><span id="line-276"></span><span class="hs-comment">-- [1,3]</span><span>
</span><span id="line-277"></span><span class="hs-comment">-- &gt;&gt;&gt; catMaybes $ map readMaybeInt [&quot;1&quot;, &quot;Foo&quot;, &quot;3&quot;]</span><span>
</span><span id="line-278"></span><span class="hs-comment">-- [1,3]</span><span>
</span><span id="line-279"></span><span class="hs-comment">--</span><span>
</span><span id="line-280"></span><span class="hs-comment">-- If we map the 'Just' constructor, the entire list should be returned:</span><span>
</span><span id="line-281"></span><span class="hs-comment">--</span><span>
</span><span id="line-282"></span><span class="hs-comment">-- &gt;&gt;&gt; mapMaybe Just [1,2,3]</span><span>
</span><span id="line-283"></span><span class="hs-comment">-- [1,2,3]</span><span>
</span><span id="line-284"></span><span class="hs-comment">--</span><span>
</span><span id="line-285"></span><span id="local-6989586621679486628"><span id="local-6989586621679486629"><span class="annot"><a href="Data.Maybe.html#mapMaybe"><span class="hs-identifier hs-type">mapMaybe</span></a></span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679486629"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486628"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679486629"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679486628"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">]</span></span></span><span>
</span><span id="line-286"></span><span id="mapMaybe"><span class="annot"><span class="annottext">mapMaybe :: forall a b. (a -&gt; Maybe b) -&gt; [a] -&gt; [b]
</span><a href="Data.Maybe.html#mapMaybe"><span class="hs-identifier hs-var hs-var">mapMaybe</span></a></span></span><span> </span><span class="annot"><span class="annottext">a -&gt; Maybe b
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-287"></span><span class="annot"><a href="Data.Maybe.html#mapMaybe"><span class="hs-identifier hs-var">mapMaybe</span></a></span><span> </span><span id="local-6989586621679486593"><span class="annot"><span class="annottext">a -&gt; Maybe b
</span><a href="#local-6989586621679486593"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679486592"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486592"><span class="hs-identifier hs-var">x</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679486591"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679486591"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-288"></span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679486590"><span class="annot"><span class="annottext">rs :: [b]
</span><a href="#local-6989586621679486590"><span class="hs-identifier hs-var hs-var">rs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; Maybe b) -&gt; [a] -&gt; [b]
forall a b. (a -&gt; Maybe b) -&gt; [a] -&gt; [b]
</span><a href="Data.Maybe.html#mapMaybe"><span class="hs-identifier hs-var">mapMaybe</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Maybe b
</span><a href="#local-6989586621679486593"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679486591"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="hs-keyword">in</span><span>
</span><span id="line-289"></span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">a -&gt; Maybe b
</span><a href="#local-6989586621679486593"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486592"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-290"></span><span>  </span><span class="annot"><span class="annottext">Maybe b
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[b]
</span><a href="#local-6989586621679486590"><span class="hs-identifier hs-var">rs</span></a></span><span>
</span><span id="line-291"></span><span>  </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679486589"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679486589"><span class="hs-identifier hs-var">r</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679486589"><span class="hs-identifier hs-var">r</span></a></span><span class="annot"><span class="annottext">b -&gt; [b] -&gt; [b]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">[b]
</span><a href="#local-6989586621679486590"><span class="hs-identifier hs-var">rs</span></a></span><span>
</span><span id="line-292"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="hs-pragma">[</span><span class="hs-pragma">1</span><span class="hs-pragma">]</span><span> </span><span class="annot"><a href="Data.Maybe.html#mapMaybe"><span class="hs-pragma hs-type">mapMaybe</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-293"></span><span>
</span><span id="line-294"></span><span class="hs-pragma">{-# RULES</span><span>
</span><span id="line-295"></span><span class="annot"><span class="hs-pragma">&quot;mapMaybe&quot;</span></span><span>     </span><span class="hs-pragma">[</span><span class="hs-pragma">~</span><span class="hs-pragma">1</span><span class="hs-pragma">]</span><span> </span><span class="hs-pragma">forall</span><span> </span><span id="local-6989586621679486588"><span class="annot"><a href="#local-6989586621679486588"><span class="hs-pragma hs-var">f</span></a></span></span><span> </span><span id="local-6989586621679486587"><span class="annot"><a href="#local-6989586621679486587"><span class="hs-pragma hs-var">xs</span></a></span></span><span class="hs-pragma">.</span><span> </span><span class="annot"><a href="Data.Maybe.html#mapMaybe"><span class="hs-pragma hs-type">mapMaybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486588"><span class="hs-pragma hs-type">f</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486587"><span class="hs-pragma hs-type">xs</span></a></span><span>
</span><span id="line-296"></span><span>                    </span><span class="hs-pragma">=</span><span> </span><span class="annot"><a href="GHC.Base.html#build"><span class="hs-pragma hs-type">build</span></a></span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">\</span><span id="local-6989586621679486586"><span class="annot"><a href="#local-6989586621679486586"><span class="hs-pragma hs-var">c</span></a></span></span><span> </span><span id="local-6989586621679486585"><span class="annot"><a href="#local-6989586621679486585"><span class="hs-pragma hs-var">n</span></a></span></span><span> </span><span class="hs-pragma">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#foldr"><span class="hs-pragma hs-type">foldr</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.Maybe.html#mapMaybeFB"><span class="hs-pragma hs-type">mapMaybeFB</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486586"><span class="hs-pragma hs-type">c</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486588"><span class="hs-pragma hs-type">f</span></a></span><span class="hs-pragma">)</span><span> </span><span class="annot"><a href="#local-6989586621679486585"><span class="hs-pragma hs-type">n</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486587"><span class="hs-pragma hs-type">xs</span></a></span><span class="hs-pragma">)</span><span>
</span><span id="line-297"></span><span class="annot"><span class="hs-pragma">&quot;mapMaybeList&quot;</span></span><span> </span><span class="hs-pragma">[</span><span class="hs-pragma">1</span><span class="hs-pragma">]</span><span>  </span><span class="hs-pragma">forall</span><span> </span><span id="local-6989586621679486583"><span class="annot"><a href="#local-6989586621679486583"><span class="hs-pragma hs-var">f</span></a></span></span><span class="hs-pragma">.</span><span> </span><span class="annot"><a href="GHC.Base.html#foldr"><span class="hs-pragma hs-type">foldr</span></a></span><span> </span><span class="hs-pragma">(</span><span class="annot"><a href="Data.Maybe.html#mapMaybeFB"><span class="hs-pragma hs-type">mapMaybeFB</span></a></span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">:</span><span class="hs-pragma">)</span><span> </span><span class="annot"><a href="#local-6989586621679486583"><span class="hs-pragma hs-type">f</span></a></span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">[</span><span class="hs-pragma">]</span><span> </span><span class="hs-pragma">=</span><span> </span><span class="annot"><a href="Data.Maybe.html#mapMaybe"><span class="hs-pragma hs-type">mapMaybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486583"><span class="hs-pragma hs-type">f</span></a></span><span>
</span><span id="line-298"></span><span>  </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-299"></span><span>
</span><span id="line-300"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">[</span><span class="hs-pragma">0</span><span class="hs-pragma">]</span><span> </span><span class="annot"><a href="Data.Maybe.html#mapMaybeFB"><span class="hs-pragma hs-type">mapMaybeFB</span></a></span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-comment">-- See Note [Inline FB functions] in GHC.List</span><span>
</span><span id="line-301"></span><span id="local-6989586621679486623"><span id="local-6989586621679486624"><span id="local-6989586621679486625"><span class="annot"><a href="Data.Maybe.html#mapMaybeFB"><span class="hs-identifier hs-type">mapMaybeFB</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679486625"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679486624"><span class="hs-identifier hs-type">r</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679486624"><span class="hs-identifier hs-type">r</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679486623"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679486625"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679486623"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679486624"><span class="hs-identifier hs-type">r</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679486624"><span class="hs-identifier hs-type">r</span></a></span></span></span></span><span>
</span><span id="line-302"></span><span id="mapMaybeFB"><span class="annot"><span class="annottext">mapMaybeFB :: forall b r a. (b -&gt; r -&gt; r) -&gt; (a -&gt; Maybe b) -&gt; a -&gt; r -&gt; r
</span><a href="Data.Maybe.html#mapMaybeFB"><span class="hs-identifier hs-var hs-var">mapMaybeFB</span></a></span></span><span> </span><span id="local-6989586621679486582"><span class="annot"><span class="annottext">b -&gt; r -&gt; r
</span><a href="#local-6989586621679486582"><span class="hs-identifier hs-var">cons</span></a></span></span><span> </span><span id="local-6989586621679486581"><span class="annot"><span class="annottext">a -&gt; Maybe b
</span><a href="#local-6989586621679486581"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621679486580"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486580"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679486579"><span class="annot"><span class="annottext">r
</span><a href="#local-6989586621679486579"><span class="hs-identifier hs-var">next</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">a -&gt; Maybe b
</span><a href="#local-6989586621679486581"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679486580"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-303"></span><span>  </span><span class="annot"><span class="annottext">Maybe b
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">r
</span><a href="#local-6989586621679486579"><span class="hs-identifier hs-var">next</span></a></span><span>
</span><span id="line-304"></span><span>  </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679486578"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679486578"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">b -&gt; r -&gt; r
</span><a href="#local-6989586621679486582"><span class="hs-identifier hs-var">cons</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679486578"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">r
</span><a href="#local-6989586621679486579"><span class="hs-identifier hs-var">next</span></a></span><span>
</span><span id="line-305"></span></pre></body></html>